package com.yxdj.service.controller;

import com.yxdj.common.core.domain.R;
import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.log.annotation.Log;
import com.yxdj.common.log.enums.BusinessType;
import com.yxdj.common.security.annotation.InnerAuth;
import com.yxdj.common.security.annotation.RequiresPermissions;
import com.yxdj.service.api.domain.ServiceDetail;
import com.yxdj.service.service.ServiceDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务详情管理
 */
@Tag(name = "服务详情管理")
@RestController
@RequestMapping("/detail")
public class ServiceDetailController extends BaseController {

    @Autowired
    private ServiceDetailService serviceDetailService;


    /**
     * 分页获取服务详情列表
     */
    @Operation(summary = "分页获取服务详情列表")
    @GetMapping("/list")
    public TableDataInfo list(ServiceDetail serviceDetail) {
        startPage();
        List<ServiceDetail> list = serviceDetailService.getPageList(serviceDetail);
        return getDataTable(list);
    }

    /**
     * 获取服务详情详细信息
     */
    @Operation(summary = "获取服务详情详细信息")
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(serviceDetailService.getById(id));
    }

    /**
     * 新增服务详情
     */
    @Operation(summary = "新增服务详情")
    @Log(title = "服务详情管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceDetail serviceDetail) {
        return toAjax(serviceDetailService.save(serviceDetail));
    }

    /**
     * 修改服务详情
     */
    @Operation(summary = "修改服务详情")
    @Log(title = "服务详情管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceDetail serviceDetail) {
        return toAjax(serviceDetailService.updateById(serviceDetail));
    }

    /**
     * 删除服务详情
     */
    @Operation(summary = "删除服务详情")
    @RequiresPermissions("system:serviceDetail:remove")
    @Log(title = "服务详情管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(serviceDetailService.removeByIds(ids));
    }

    @InnerAuth
    @Operation(summary = "供微服务内部远程调用根据id查询服务详情的方法")
    @GetMapping("/app/getServiceDetailById/{id}")
    public R<ServiceDetail> getServiceDetailById(@PathVariable(name = "id") Long id)
    {
        ServiceDetail serviceDetail = serviceDetailService.getById(id);
        return R.ok(serviceDetail);
    }
}
